package com.itheima.appserver.controller;

import com.itheima.appserver.service.TanhuaService;
import com.itheima.model.dto.RecommendUserDto;
import com.itheima.model.vo.NearUserVo;
import com.itheima.model.vo.PageResult;
import com.itheima.model.vo.TodayBest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/tanhua")
public class TanhuaController {

    @Autowired
    private TanhuaService tanhuaService;

    //今日佳人
    @GetMapping("/todayBest")
    public ResponseEntity todayBest() {
        TodayBest vo = tanhuaService.todayBest();
        return ResponseEntity.ok(vo);
    }

    //推荐用户列表
    @GetMapping("/recommendation")
    public ResponseEntity recommendation(RecommendUserDto dto) {
        //根据分页返回vo对象
        PageResult pr = tanhuaService.recommendation(dto);
        return ResponseEntity.ok(pr);
    }

    //查看佳人信息
    @GetMapping("/{id}/personalInfo")
    public ResponseEntity personalInfo(@PathVariable("id") Long userId) {
        //调用service查询佳人信息以及缘分值
        TodayBest best = tanhuaService.findbest(userId);
        return ResponseEntity.ok(best);
    }

    //查询陌生人问题
    @GetMapping("/strangerQuestions")
    public ResponseEntity strangerQuestions(Long userId) {
        String question = tanhuaService.findQue(userId);
        return ResponseEntity.ok(question);
    }

    //回复陌生人问题
    @PostMapping("/strangerQuestions")
    public ResponseEntity replyQuestions(@RequestBody Map map) {
        //获取用户id,因为前端传递的userid是interager类型
        String obj = map.get("userId").toString();
        Long userId = Long.valueOf(obj);
        //获取用户问题
        String reply = (String) map.get("reply");
        //调用service
        tanhuaService.replyQuestions(userId, reply);
        return ResponseEntity.ok(null);
    }

    //探花推荐列表
    @GetMapping("/cards")
    public ResponseEntity cards() {
        List<TodayBest> list = tanhuaService.cards();
        return ResponseEntity.ok(list);
    }

    //喜欢
    @GetMapping("/{id}/love")
    public ResponseEntity love(@PathVariable("id") Long likeUserId) {
        //调用service喜欢
        tanhuaService.love(likeUserId);
        return ResponseEntity.ok(null);
    }

    //不喜欢
    @GetMapping("/{id}/unlove")
    public ResponseEntity unlove(@PathVariable("id") Long likeUserId) {
        //调用service喜欢
        tanhuaService.unlove(likeUserId);
        return ResponseEntity.ok(null);
    }

    //搜附近
    @GetMapping("search")
    public ResponseEntity search(String gender,
                                 @RequestParam(defaultValue = "2000") String distance) {
        List<NearUserVo> vo = tanhuaService.search(gender, distance);
        return ResponseEntity.ok(vo);

    }
}